import json
import os
class FileHander:
    
    def __init__(self, path_dir):
        self.path_dir = path_dir
        
    def _get_file(self):
        files = os.listdir(self.path_dir)
        for file in (file for file in files if file.endswith('.har')):
            yield os.path.join(self.path_dir,".\\"+file)
            
    def _get_context(self):
        for file in self._get_file():
            with open( file, 'r', encoding='UTF-8') as f:
                context = f.read()
                yield context
                
    def get_entry(self):
        for context in self._get_context():
            f_json = json.loads(context)
            entries = f_json['log']['entries']
            for entry in entries:
                yield entry
                
    def handle(self):
        with open('.\www.baidu.com.har','r',encoding='UTF-8') as f:
            context = f.read()
            f_json = json.loads(context)
            entries = f_json['log']['entries']
            for entry in entries:
                print(entry['request']['url'])
'''
if __name__ == '__main__':
    fh = FileHander(".")
    for entry in fh.get_entry():
        print(entry['request']['url'])
'''